<!doctype html>
<html class="no-js" manifest="__PUBLIC__/home/manifest/test.manifest">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <title>我的信息</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="绵阳中学英才学校" />
    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileColor" content="#0e90d2">
    <link rel="stylesheet" href="__PUBLIC__/home/css/amazeui.min.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/enrolling.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/contribute.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/registrationform.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/user_update.css">
</head>
<body>
    <!-- 头部 -->
    <header data-am-widget="header" class="am-header am-header-default">
      <div class="am-header-left am-header-nav">
        <a href="javascript:history.go(-1);" class="am-header-left1">
          <img src="__PUBLIC__/home/images/back.png" alt="">
        </a>
      </div>

      <h3 class="am-header-title">
          <a href="#title-link" class="">
            我的信息
          </a>
      </h3>

    </header>

    <!-- 中间 -->
    <div class="content">
      <div class="content2">
        <div class="content2_title am-g content2_title_out">
            <div class="am-u-sm-5">
              <div class="xiugai_touxiang">
                <h3>头像</h3><br>
              </div>
            </div>
            <!-- 添加头像 -->
            <div id="file" class="am-u-sm-7 file_right">
              <img src="__PUBLIC__/home/images/upload.png" alt="" class="filebtn" id="filebtn" />
              <input accept="image/*"  capture="camera" id='upfile' class="upfile" name="upfile" type="file" />
            </div>
            <div id="pic_url">
            	
            </div>
        </div>
        <div class="content2_title am-g content2_title_out">
            <div class="am-u-sm-5">
              <div><h3>昵称</h3></div>
            </div>
            <div class="am-u-sm-7">
              <input name="nickname" type="text">
            </div>
        </div>
        <div class="content2_title am-g content2_title_out">
            <div class="am-u-sm-5">
              <div><h3>座右铭</h3></div>
            </div>
            <div class="am-u-sm-7">
              <input name="mottos" type="text">
            </div>
        </div>
        <div class="am-g xiugai_btn">
          <button class="am-u-sm-11 true_xiugai am-u-sm-centered" id="btn">确定修改</button>
        </div>
      </div>
    </div>

    <!-- 底部 -->
      <include file="Public:footer" />

    <script src="__PUBLIC__/home/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/js/amazeui.min.js"></script>
    <script src="__PUBLIC__/home/js/limit.js"></script>
    <script src="__PUBLIC__/home/js/footer.js"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.ui.widget.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.fileupload.js"></script>
    <script type="text/javascript">
    	var re_nic = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;//昵称验证
    	var re_m = /^[\u4E00-\u9FA5]+$/;
    	function check_form(){
    		if($("input[name=nickname]").val()!=''){
    			if($("input[name=nickname]").val().length < 3 || $("input[name=nickname]").val().length>6 ||!re_nic.test($("input[name=nickname]").val())){
    				alert('昵称为3到6位，中文、字母、数字下划线组成');
    				$("input[name=nickname]").val().focus();
    				return false;
    			}
    		}
    		if($("input[name=mottos]").val()!=''){
    			if($("input[name=nickname]").val().length>15 ||!re_m.test($("input[name=mottos]").val())){
    				alert('座右铭为于15位，中文组成');
    				$("input[name=mottos]").focus();
    				return false;
    			}
    		}
    		return true;
    	}
    	$(function(){
    		$('#upfile').fileupload({
                dataType: 'json',//数据类型：json
                url: '__APP__/Enroll/upload',//上传地址
                formData: {name:'upfile'},
                add: function (e,data) {
                    data.submit();
                },
                done: function (e,data) {
                    var param = data.result;
                    console.log(param);
                   if (typeof(param.error) != 'undefined') {
                        alert(param.error);//弹出错误
                    }else{
                    		var leng = param[0].savepath.length-1;
                    		var html="<input type='hidden' name='pic_url' value='"+param[0].savepath.substr(1,leng)+param[0].savename+"' />";
                    		$('#filebtn').attr('src','__ROOT__'+param[0].savepath.substr(1,leng)+param[0].savename);//显示上传的图片
                    		$('#pic_url').html(html);
                   }
                }
            });
    		$('#btn').click(function(){
    				var nickname=$("input[name=nickname]").val();
    				var mottos=$("input[name=mottos]").val();
    				var pic_url = $("input[name=pic_url]").val();
    				if(check_form()){
	    				$.ajax({
	    					type:"POST",
	    					url:"{:U('User/user_update')}",
	    					data:{'pic_url':pic_url,'nickname':nickname,'mottos':mottos},
	    					success:function(data){
	    						if(data==1){
	    							alert('修改成功');
	    							window.location.href = '__APP__/User/user_center';
	    						}else{
	    							alert('失败');
	    						}
	    					}
	    				});
    				}
    		});
    	});
    </script>
</body>

</html>
